#include <QSettings>
#include "settingsdialog.h"
#include "ui_settingsdialog.h"

settingsDialog::settingsDialog(QWidget *parent) : QDialog(parent), m_ui(new Ui::settingsDialog)
{
    m_ui->setupUi(this);
    connect(this, SIGNAL(accepted()), this, SLOT(saveSettings()));
    this->loadSettings();
}

void settingsDialog::loadSettings() {
    QSettings settings("dmitryduka", "ContactsList");
    m_ui->emailLine->setText(settings.value("email", QString()).toString());
    m_ui->passwdLine->setText(settings.value("password", QString()).toString());
    if(settings.value("open", "browser").toString() == "browser") m_ui->browserRadio->setChecked(true);
    else m_ui->mailClientRadio->setChecked(true);
}

void settingsDialog::saveSettings() {
    QSettings settings("dmitryduka", "ContactsList");
    settings.setValue("email", m_ui->emailLine->text());
    settings.setValue("password", m_ui->passwdLine->text());
    if(m_ui->browserRadio->isChecked()) settings.setValue("open", "browser");
    else settings.setValue("open", "mail");
}

settingsDialog::~settingsDialog() { delete m_ui; }

void settingsDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
